package com.gugee.ins.common.dal.mapper.statistics;

import com.gugee.common.mapper.GugeeMapper;

import com.gugee.ins.common.model.mysql.statistics.InsStBloggerIncome;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * InsStBloggerIncomeMapper
 * @author Huangxin
 */
public interface InsStBloggerIncomeMapper extends GugeeMapper<InsStBloggerIncome> {
    /**
     * 根据uid 获取收入统计信息
     * @param uid
     * @return
     */
    @Select("select #{uid} uid,tt1.income,IFNULL(tt2.nums,0)income_rate from ins_dic_income tt1 " +
            " left join (select t2.income,count(1) nums from " +
            " (select distinct f_uid from ins_rel_blogger_active_follower where uid = #{uid}) t1 " +
            " inner join ins_blogger t2 on t1.f_uid = t2.uid where t2.income is not null group by t2.income)tt2 " +
            " on tt1.income = tt2.income " +
            " order by nums desc ")
    List<InsStBloggerIncome> findIncomeByUid(@Param("uid")long uid);

    /**
     * 根据uid 删除收入统计信息
     * @param uid
     * @return
     */
    @Delete("delete from ins_st_blogger_income where uid = #{uid} ")
    void deleteByUid(@Param("uid")long uid);
}